// index.js
// 获取应用实例
import { getSwipeImg, getTodayGoods } from '../../utils/commend'
const app = getApp()

Page({
  data: {
    indicatorDots: true,
    autoplay: true,
    vertical: false,
    interval: 2000,
    duration: 500,
    webp: true,
    Item: [],
    goods: []
  },
  // 事件处理函数
  bindViewTap() {
    wx.navigateTo({
      url: '../logs/logs'
    })
  },
  onLoad() {
   console.log('onload')
  },
  onShow() {
    this.getImg()
    this.getToday()
  },
  getUserInfo(e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  },
  // 获取轮播图
  async getImg () {
    let res = await getSwipeImg({
      platform: 'mini'
    })
    this.setData({
      Item: res.items
    })
  },
  // 获取当日上架商品
  async getToday () {
    let res = await getTodayGoods({
      // time: 'today',
      platform: 'mini'
    })
    console.log(res)
    this.setData({
      goods: res.items
    })
  },
  toDetail (e) {
    wx.navigateTo({
      url: `../retail/retail?id=${e.currentTarget.dataset.item}`
      // url: '../retail/retail'
    })
    console.log('iiii', e.currentTarget.dataset.item)
  }
})
